<template>
	<view class="content">
		<view class="row b-b">
			<text class="tit">提货人</text>
			<input class="input" type="text" v-model="addressData.name" placeholder="提货人" placeholder-class="placeholder" />
		</view>
		<view class="row b-b">
			<text class="tit">手机号</text>
			<input class="input" type="number" v-model="addressData.phone" placeholder="手机号" placeholder-class="placeholder" />
		</view>
	
		
		<view class="row default-row">
			<text class="tit">
				<view>
					设为默认提货人
				</view>
				<view style="color:#797979;font-size:20rpx;padding-top:6rpx;">
					每次下单会默认使用该提货人
				</view>
			</text>
			<switch :checked="addressData.is_default" color="#fa436a" @change="switchChange" />
		</view>
		<view class="del-wrap" v-if="title == '编辑提货人'">
			<view @click="deltihuoren">
				删除此提货人
			</view>
		</view>
		<button class="add-btn" @click="confirm">保存</button>
		<selectAddress ref='selectAddress' @selectAddress="successSelectAddress"></selectAddress>
	</view>
</template>

<script>
	import selectAddress from '@/components/yixuan-selectAddress/yixuan-selectAddress.vue'
	export default {
		components:{
			selectAddress
		},
		data() {
			return {
				title:'',
				addressData: {
					name: '',
					phone: '',
					
					
					is_default: false
				}
			}
		},
		onLoad(option){
			let title = '新增提货人';
			this.title='新增提货人'
			if(option.type==='edit'){
				title = '编辑提货人'
				this.title='编辑提货人'
				this.addressData = JSON.parse(option.data)
			}
			this.manageType = option.type;
			uni.setNavigationBarTitle({
				title
			})
		},
		methods: {
			deltihuoren(){
				let that=this
				uni.showModal({
					title: '提示',
					content: '确认删除？',
					success: function (res) {
						if (res.confirm) {
								that.apiget('/api/home/delete_pick_up',{id:that.addressData.id}).then(res => {
									if(res.Code==10200){
										uni.showToast({
										    title: res.Message,
										    duration:4000,
											icon:'none'
										});
										uni.navigateBack()
									}
								
								}).catch(err=>{
								console.log(err)
								});
								
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			successSelectAddress(address){
				
				this.addressData.area=address
				//console.log(this.addressObj.area)
				
			},
			chooseLocation(){
				this.$refs.selectAddress.show()
			},
			switchChange(e){
				this.addressData.is_default = e.detail;
			},
			
			
			
			//提交
			confirm(){
				let data = this.addressData;
				// if(!data.name){
					
				// 	return;
				// }
				
				// if(!data.address){
					
				// 	return;
				// }
				// if(!data.area){
					
				// 	return;
				// }
				
				let that=this
				that.apipost('/api/home/submit_pick_up',data,true).then(res => {
					if(res.Code==10200){
						uni.showToast({
						    title: res.Message,
						    duration:4000,
							icon:'none'
						});
						uni.navigateBack()
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: $page-color-base;
		padding-top: 16rpx;
	}
	.del-wrap{
		color:#e80435;
		padding-top:50rpx;
		display:flex;
		justify-content: center;
	}
	.row{
		display: flex;
		align-items: center;
		position: relative;
		padding:0 30rpx;
		min-height: 110rpx;
		background: #fff;
		
		.tit{
			flex-shrink: 0;
			width: 120rpx;
			font-size: 30rpx;
			color: $font-color-dark;
		}
		.input{
			flex: 1;
			font-size: 30rpx;
			color: $font-color-dark;
		}
		.icon-shouhuodizhi{
			font-size: 36rpx;
			color: $font-color-light;
		}
	}
	.default-row{
		margin-top: 16rpx;
		.tit{
			flex: 1;
		}
		switch{
			transform: translateX(16rpx) scale(.9);
		}
	}
	.add-btn{
		left:30rpx;
		bottom:30rpx;
		position:fixed;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690rpx;
		height: 80rpx;
		margin: 60rpx auto;
		font-size: $font-lg;
		color: #fff;
		background-color: $base-color;
		border-radius: 10rpx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
</style>

